package com.lqw.vhr.service;

import com.lqw.vhr.mapper.EmployeeMapper;
import com.lqw.vhr.mapper.EmployeeremoveMapper;
import com.lqw.vhr.model.AdjustSalary;
import com.lqw.vhr.model.Employee;
import com.lqw.vhr.model.Employeeremove;
import com.lqw.vhr.model.RespPageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmpMoveService {

    @Autowired
    EmployeeremoveMapper employeeremoveMapper;

    @Autowired
    EmployeeMapper employeeMapper;

    public RespPageBean getEmpMoveByPage(Integer page, Integer size, String keyword) {
        if (page != null && size != null) {
            page = (page - 1) * size;
        }
        List<Employeeremove> adjustSalaries = employeeremoveMapper.getEmpMoveByPage(page, size, keyword);
        long total = employeeremoveMapper.countEmpMoveByPage(page, size, keyword);
        RespPageBean respPageBean = new RespPageBean();
        respPageBean.setData(adjustSalaries);
        respPageBean.setTotal(total);
        return respPageBean;
    }

    public int updateEmpRemove(Employeeremove employeeremove) {
        Integer deptId = employeeremove.getAfterDepId();
        Integer posId = employeeremove.getAfterJobId();
        Employee employee = new Employee();
        employee.setId(employeeremove.getEid());
        employee.setDepartmentId(deptId);
        employee.setPosId(posId);
        employeeMapper.updateByPrimaryKeySelective(employee);
        return employeeremoveMapper.updateByPrimaryKeySelective(employeeremove);
    }

    public int addEmpRemove(Employeeremove employeeremove) {
        return employeeremoveMapper.insertSelective(employeeremove);
    }

    public int deleteEmpRemoveById(Integer id) {
        return employeeremoveMapper.deleteByPrimaryKey(id);
    }


}
